<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<style>
	.typeoption{
		width:auto;margin-top:30px;
	}
	.datetimeip{float:left;width:113px;height:20px;background:#eeeeee;border:1px solid #cfcfcf;position:relative;display:block;}
	.datetimeip input.dateip{float:left;width:90px;height:13px;margin-left:5px;margin-top:5px; background:none repeat scroll 0 50% transparent;border:0 none;color: #000000; font-size: 12px;}
	.datetimeip input.buttonicon{float:left;width:20px;height:20px;margin: 6px 0 0 7px;margin: 6px 0 0 4px\9;border:0 none;cursor: pointer;}
	.datetimebt{float:left;width:50px;height:23px;font-size: 12px;background:#006699;border:1px solid #b1c0cb;display:block;text-align:center;font-weight:bold;cursor:pointer;color:#FFF;margin-left:30px;}
	.ui-datepicker-trigger{margin-top:2px;cursor:pointer;}
	
	table.summary{width:99%;float:left;margin-top:15px;border:1px solid #cfcfcf;}
	table.summary thead td{font-weight:bold;padding-left:10px;background:#eeeeee;border-right:1px solid #cfcfcf;border-bottom:1px solid #cfcfcf;}
	table.summary tbody td{padding-left:10px;border:1px solid #cfcfcf;}
	table tbody tr:nth-child(2n){background:#fff;}
</style>

<?php 
	$ci = & get_instance();
	if(!isUserLogin()){
		redirect(site_url());exit();
	}
	//$history_array = $ci->bet_entity->getBetHistory($_SESSION['user']['id']);
	$betResultArray = betResultDataConfig();
	$typeOption = array('settled'=> 'Settled Predictions','unsettled'=> 'Unsettled Predictions');
	$betTypeArray = getPredictTypeDataConfig();
	
	$bet_type = in_array($this->input->get('bet_type',FALSE),array_keys($betTypeArray)) ? $this->input->get('bet_type',FALSE) : 'predefined' ;
	$type = in_array($this->input->get('type',FALSE),array_keys($typeOption)) ? $this->input->get('type',FALSE):'settled';
	$mode = in_array($this->input->get('mode',FALSE),array('m1','m2')) ? $this->input->get('mode',FALSE):'m1';
	
	$checked1 = ($mode == 'm1') ? 'checked="checked"':'';
	$checked2 = ($mode == 'm2') ? 'checked="checked"':'';
	$fromDate = $this->input->get('fromDate',FALSE);
	$toDate = $this->input->get('toDate',FALSE);
?>
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 style="font-weight:bold;"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Prediction History</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
		</div>
		<div class="clrboth"></div>
		<div class="content">
		<div class="rowitem3">
			<form action="<?php echo site_url('cricket/account/predict_history');?>" name="bet_history" id="bet_history" method="get" >
				History Type: 
				<?php 
					echo form_dropdown( 'type',
									$options = $typeOption,
									$selected = array($type),
									"id='type' class='typeoption'"
								);
				?>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Predict Type:
				<?php 
					echo form_dropdown( 'bet_type',
									$options = getPredictTypeDataConfig(),
									$selected = array($bet_type),
									"id='bet_type' class='typeoption'"
								);
				?>
				<div class="clrboth" style="height:20px;"></div>
				<div style="float:left;">
					<input type="radio" name="mode" id="last24h" value="m1" <?php echo $checked1;?> /> Last 24 hours
					&nbsp;&nbsp;&nbsp;
					<input type="radio" name="mode" id="sltime" value="m2" <?php echo $checked2;?> /> From
					&nbsp;&nbsp;
				</div>
				<div class="datetimeip" style="margin-left:10px;">
					<input type="text" class="dateip" id="fromDate" name="fromDate" value="<?php echo $fromDate;?>" />
				</div>
				<span class="left" style="margin-left:15px;">to</span>
				<div class="datetimeip" style="margin-left:15px;">
					<input type="text" class="dateip" id="toDate" name="toDate" value="<?php echo $toDate;?>" />
				</div>
				<input type="submit" value="GO" class="datetimebt" />
				 
			</form>	
			<div class="clrboth" style="height:20px;"></div>
			<?php if($bet_type == 'all'):?>
				<?php $predefined = $this->cricket_m->bet_history('predefined', $this->input->get('type',TRUE), $this->input->get('mode',TRUE), $this->input->get('fromDate',TRUE), $this->input->get('toDate',TRUE));?>
				<?php if($predefined): ?>
					<?php echo $betTypeArray['predefined'];?><br/>
					<table class="summary">
						<thead>
							<td width="20%">Category</td>
							<td width="20%">Event name & Probability Points</td>
							<td width="20%">Date/Time</td>
							<td width="10%">Coins</td>
							<td width="15%">Points Won</td>
							<td width="15%">Result</td>
						</thead>	
						<tbody>
							<?php foreach($predefined as $item):?>
								<?php 
									$EVENT = $ci->event_entity->init('id',$item->event_id);
									$MATCH = $ci->match_entity->init('id',$item->match_id);
									$HOME = clone_($ci->team_entity->init('id',$MATCH->getHome()));
									$AWAY = clone_($ci->team_entity->init('id',$MATCH->getAway()));
									$EVENT_CATEGORY = $ci->event_category_entity->init('id',$EVENT->getEventCategoryId());
								?>
								<tr>
									<td width="20%">
										<?php echo $EVENT_CATEGORY->getCategory();?>
									</td>
									<td width="20%">
										<?php echo $EVENT->getName();?><br/>
										<?php echo $item->odds;?> P
									</td>
									<td width="20%"><?php echo indiaDateTime($item->bet_time);?></td>
									<td width="10%" style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
									<td width="15%" style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
									<td width="15%" ><?php echo $betResultArray[$item->result];?></td>
								</tr>
							<?php endforeach;?>
						</tbody>	
					</table>	
				<?php endif;?>
				
				<div class="clrboth" style="height:10px;"></div>
				
				<?php $manual = $this->cricket_m->bet_history('manual', $this->input->get('type',TRUE), $this->input->get('mode',TRUE), $this->input->get('fromDate',TRUE), $this->input->get('toDate',TRUE));?>
				<?php if($manual): ?>
					<?php echo $betTypeArray['manual'];?><br/>
					<table class="summary">
					<thead>
						<td width="20%">Category</td>
						<td width="15%">Match</td>
						<td width="20%">Answer</td>
						<td width="15%">Date/Time</td>
						<td width="10%">Stake</td>
						<td width="10%">Points Won</td>
						<td width="10%">Result</td>
					</thead>	
					<tbody>
						<?php foreach($manual as $item):?>
							<?php 
								$CAT_MANUAL = $ci->category_manual_entity->init('key_id',$item->category_id);
								$MATCH = $ci->match_entity->init('id',$item->match_id);
								$HOME = clone_($ci->team_entity->init('id',$MATCH->getHome()));
								$AWAY = clone_($ci->team_entity->init('id',$MATCH->getAway()));
								$BET_MANUAL = clone_($ci->bet_manual_entity->init('id',$item->id));
								
								$ishow = true;
								if($CAT_MANUAL->getType() == 'box'){
									$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
									if($answer_array){
										$ishow = true;
									}else{
										$ishow = false;
									}
								}
							?>
							<?php if($ishow):?>
								<tr>
									<td>
										<?php echo $CAT_MANUAL->getCategoryName();?><br/>
										<?php echo $item->odds;?> P
									</td>
									<td>
										<?php echo ( $HOME->getCode() ) ? $HOME->getCode() : $HOME->getName() ;?> Vs
										<?php echo ( $AWAY->getCode() ) ? $AWAY->getCode() : $AWAY->getName() ;?> <br/>
										ID: <?php echo $CAT_MANUAL->getKeyId() ;?>
									</td>
									<td>
										<?php 
											if($CAT_MANUAL->getType() == 'box'){
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												foreach($answer_array as $one){
													echo "- ".$one."<br/>";
												}
											}else{
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												echo "From ".$answer_array[0]." To ".$answer_array[1];
											}
										?>
									</td>
									<td><?php echo indiaDateTime($item->bet_time);?></td>
									<td style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
									<td style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
									<td><?php echo $betResultArray[$item->result];?></td>
								</tr>
							<?php endif; ?>	
						<?php endforeach;?>
					</tbody>	
				</table>	
				<?php endif;?>
				
				<div class="clrboth" style="height:10px;"></div>
				
				<?php $tournament = $this->cricket_m->bet_history('tournament', $this->input->get('type',TRUE), $this->input->get('mode',TRUE), $this->input->get('fromDate',TRUE), $this->input->get('toDate',TRUE));?>
				<?php if($tournament): ?>
					<?php echo $betTypeArray['tournament'];?><br/>
					<table class="summary">
						<thead>
							<td width="20%">Event name & Probability Points</td>
							<td width="20%">Tournament</td>
							<td width="20%">Date/Time</td>
							<td width="10%">Coins</td>
							<td width="15%">Points Won</td>
							<td width="15%">Result</td>
						</thead>	
						<tbody>
							<?php foreach($tournament as $item):?>
								<?php 
									$EVENT = $ci->event_tournament_entity->init('id',$item->event_id);
									$TOURNAMENT = $ci->tournament_entity->init('id',$item->tournament_id);
									$EVENT_CATEGORY = $ci->event_category_tournament_entity->init('id',$EVENT->getTournamentEventCategoryId());
								?>
								<tr>
									<td width="20%">
										<?php echo $EVENT->getName();?><br/>
										<?php echo $item->odds;?> P
									</td>
									<td width="20%"><?php echo $TOURNAMENT->getName();?></td>
									<td width="20%"><?php echo indiaDateTime($item->bet_time);?></td>
									<td width="10%" style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
									<td width="15%" style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
									<td width="15%" ><?php echo $betResultArray[$item->result];?></td>
								</tr>
							<?php endforeach;?>
						</tbody>	
					</table>	
				<?php endif;?>
				
				<div class="clrboth" style="height:10px;"></div>
				
				<?php $manual_tournament = $this->cricket_m->bet_history('manual_tournament', $this->input->get('type',TRUE), $this->input->get('mode',TRUE), $this->input->get('fromDate',TRUE), $this->input->get('toDate',TRUE));?>
				<?php if($manual_tournament): ?>
					<?php echo $betTypeArray['manual_tournament'];?><br/>
					<table class="summary">
						<thead>
							<td width="20%">Category</td>
							<td width="15%">Tournament</td>
							<td width="20%">Answer</td>
							<td width="15%">Date/Time</td>
							<td width="10%">Stake</td>
							<td width="10%">Points Won</td>
							<td width="10%">Result</td>
						</thead>	
						<tbody>
						 
							<?php foreach($items as $item):?>
								<?php 
									$CAT_MANUAL = $ci->category_manual_tournament_entity->init('key_id',$item->category_id);
									$TOURNAMENT = $ci->tournament_entity->init('id',$item->tournament_id);
									$BET_MANUAL = $ci->bet_manual_tournament_entity->init('id',$item->id);
									
									$ishow = true;
									if($CAT_MANUAL->getType() == 'box'){
										$answer_array = (explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
										if($answer_array){
											$ishow = true;
										}else{
											$ishow = false;
										}
									}
								?>
								<?php if($ishow):?>
									<tr>
										<td>
											<?php echo $CAT_MANUAL->getCategoryName();?><br/>
											<?php echo $item->odds;?> P
										</td>
										<td><?php echo $TOURNAMENT->getName();?></td>
										<td>
											<?php 
												if($CAT_MANUAL->getType() == 'box'){
													$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
													foreach($answer_array as $one){
														echo "- ".$one."<br/>";
													}
												}else{
													$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
													echo "From ".intval($answer_array[0])." To ".$answer_array[1];
												}
											?>
										</td>
										<td><?php echo indiaDateTime($item->bet_time);?></td>
										<td style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
										<td style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
										<td><?php echo $betResultArray[$item->result];?></td>
									</tr>
								<?php endif; ?>	
							<?php endforeach;?>
						</tbody>	
					</table>	
				<?php endif;?>
			<?php endif;?>
			
			<?php if($bet_type == 'predefined'):?>
				<table class="summary">
					<thead>
						<td width="20%">Category</td>
						<td width="20%">Event name & Probability Points</td>
						<td width="20%">Date/Time</td>
						<td width="10%">Coins</td>
						<td width="15%">Points Won</td>
						<td width="15%">Result</td>
					</thead>	
					<tbody>
						<?php foreach($items as $item):?>
							<?php 
								$EVENT = $ci->event_entity->init('id',$item->event_id);
								$MATCH = $ci->match_entity->init('id',$item->match_id);
								$HOME = clone_($ci->team_entity->init('id',$MATCH->getHome()));
								$AWAY = clone_($ci->team_entity->init('id',$MATCH->getAway()));
								$EVENT_CATEGORY = $ci->event_category_entity->init('id',$EVENT->getEventCategoryId());
							?>
							<tr>
								<td width="20%">
									<!--
									<?php //echo ( $HOME->getCode() ) ? $HOME->getCode() : $HOME->getName() ;?> Vs
									<?php //echo ( $AWAY->getCode() ) ? $AWAY->getCode() : $AWAY->getName() ;?> <br/>
									ID: <?php //echo $EVENT_CATEGORY->getKeyId()? $EVENT_CATEGORY->getKeyId():$EVENT->getEventCategoryId();?>
									-->
									<?php echo $EVENT_CATEGORY->getCategory();?>
								</td>
								<td width="20%">
									<?php echo $EVENT->getName();?><br/>
									<?php echo $item->odds;?> P
								</td>
								<td width="20%"><?php echo indiaDateTime($item->bet_time);?></td>
								<td width="10%" style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
								<td width="15%" style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
								<td width="15%" ><?php echo $betResultArray[$item->result];?></td>
							</tr>
						<?php endforeach;?>
					</tbody>	
				</table>	
			<?php endif;?>
			
			<?php if($bet_type == 'manual'):?>
				<table class="summary">
					<thead>
						<td width="20%">Category</td>
						<td width="15%">Match</td>
						<td width="20%">Answer</td>
						<td width="15%">Date/Time</td>
						<td width="10%">Stake</td>
						<td width="10%">Points Won</td>
						<td width="10%">Result</td>
					</thead>	
					<tbody>
					 
						<?php foreach($items as $item):?>
							<?php 
								$CAT_MANUAL = $ci->category_manual_entity->init('key_id',$item->category_id);
								$MATCH = $ci->match_entity->init('id',$item->match_id);
								$HOME = clone_($ci->team_entity->init('id',$MATCH->getHome()));
								$AWAY = clone_($ci->team_entity->init('id',$MATCH->getAway()));
								$BET_MANUAL = clone_($ci->bet_manual_entity->init('id',$item->id));
								
								$ishow = true;
								if($CAT_MANUAL->getType() == 'box'){
									$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
									if($answer_array){
										$ishow = true;
									}else{
										$ishow = false;
									}
								}
							?>
							<?php if($ishow):?>
								<tr>
									<td>
										<?php echo $CAT_MANUAL->getCategoryName();?><br/>
										<?php echo $item->odds;?> P
									</td>
									<td>
										<?php echo ( $HOME->getCode() ) ? $HOME->getCode() : $HOME->getName() ;?> Vs
										<?php echo ( $AWAY->getCode() ) ? $AWAY->getCode() : $AWAY->getName() ;?> <br/>
										ID: <?php echo $CAT_MANUAL->getKeyId() ;?>
									</td>
									<td>
										<?php 
											if($CAT_MANUAL->getType() == 'box'){
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												foreach($answer_array as $one){
													echo "- ".$one."<br/>";
												}
											}else{
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												echo "From ".$answer_array[0]." To ".$answer_array[1];
											}
										?>
									</td>
									<td><?php echo indiaDateTime($item->bet_time);?></td>
									<td style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
									<td style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
									<td><?php echo $betResultArray[$item->result];?></td>
								</tr>
							<?php endif; ?>	
						<?php endforeach;?>
					</tbody>	
				</table>	
			<?php endif;?>
			
			<?php if($bet_type == 'tournament'):?>
				<table class="summary">
					<thead>
						<td width="20%">Event name & Probability Points</td>
						<td width="20%">Tournament</td>
						<td width="20%">Date/Time</td>
						<td width="10%">Coins</td>
						<td width="15%">Points Won</td>
						<td width="15%">Result</td>
					</thead>	
					<tbody>
					 	<?php foreach($items as $item):?>
							<?php 
								$EVENT = $ci->event_tournament_entity->init('id',$item->event_id);
								$TOURNAMENT = $ci->tournament_entity->init('id',$item->tournament_id);
								$EVENT_CATEGORY = $ci->event_category_tournament_entity->init('id',$EVENT->getTournamentEventCategoryId());
							?>
							<tr>
								<td width="20%">
									<?php echo $EVENT->getName();?><br/>
									<?php echo $item->odds;?> P
								</td>
								<td width="20%"><?php echo $TOURNAMENT->getName();?></td>
								<td width="20%"><?php echo indiaDateTime($item->bet_time);?></td>
								<td width="10%" style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
								<td width="15%" style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
								<td width="15%" ><?php echo $betResultArray[$item->result];?></td>
							</tr>
						<?php endforeach;?>
					</tbody>	
				</table>	
			<?php endif;?>
			
			<?php if($bet_type == 'manual_tournament'):?>
				<table class="summary">
					<thead>
						<td width="20%">Category</td>
						<td width="15%">Tournament</td>
						<td width="20%">Answer</td>
						<td width="15%">Date/Time</td>
						<td width="10%">Stake</td>
						<td width="10%">Points Won</td>
						<td width="10%">Result</td>
					</thead>	
					<tbody>
					 
						<?php foreach($items as $item):?>
							<?php 
								$CAT_MANUAL = $ci->category_manual_tournament_entity->init('key_id',$item->category_id);
								$TOURNAMENT = $ci->tournament_entity->init('id',$item->tournament_id);
								$BET_MANUAL = $ci->bet_manual_tournament_entity->init('id',$item->id);
								
								$ishow = true;
								if($CAT_MANUAL->getType() == 'box'){
									$answer_array = (explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
									if($answer_array){
										$ishow = true;
									}else{
										$ishow = false;
									}
								}
							?>
							<?php if($ishow):?>
								<tr>
									<td>
										<?php echo $CAT_MANUAL->getCategoryName();?><br/>
										<?php echo $item->odds;?> P
									</td>
									<td><?php echo $TOURNAMENT->getName();?></td>
									<td>
										<?php 
											if($CAT_MANUAL->getType() == 'box'){
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												foreach($answer_array as $one){
													echo "- ".$one."<br/>";
												}
											}else{
												$answer_array = array_filter(explode('{[|SEPSTR|]}',$BET_MANUAL->getAnswer()));
												echo "From ".intval($answer_array[0])." To ".$answer_array[1];
											}
										?>
									</td>
									<td><?php echo indiaDateTime($item->bet_time);?></td>
									<td style="text-align:right;"><?php echo $item->stake;?>&nbsp;</td>
									<td style="text-align:right;"><?php echo bet_format($item->point_get);?>&nbsp;</td>
									<td><?php echo $betResultArray[$item->result];?></td>
								</tr>
							<?php endif; ?>	
						<?php endforeach;?>
					</tbody>	
				</table>	
			<?php endif;?>
			
		</div>	 
		<div class="clrboth"></div>
		</div>
	</div>	
	<div class="clrboth"></div>
</div>

<script type="text/javascript">
	var sgm = '<?php echo $this->input->get('bet_type',TRUE); ?>';
	if(!sgm){
			queryURL(BASE_URI+'cricket/account/predict_history?type=settled&bet_type=all&mode=m1&fromDate=&toDate=');
		}
	google.setOnLoadCallback(function(){
		$( "#fromDate,#toDate" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd/mm/yy',
			showOn: "button",
			buttonImage: BASE_URI+"addons/default/themes/clicxa/css/images/calendar.png",
			buttonImageOnly: true,
			buttonText: 'Choose date'
		});
		
	
	});
</script>	